package com.qf.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.service.Contact;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

@Configuration
@EnableConfigurationProperties(QfsyProperties.class)
public class Qfsy2203AutoFigure {

    @Autowired
    QfsyProperties qfsyProperties;


    @Bean
    public Docket docket(){

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(getApiInfo())
                .select()
                //指定swagger扫描的包路径
                .apis(RequestHandlerSelectors.basePackage(qfsyProperties.getBasepackage()))
                .build();
    }

    private ApiInfo getApiInfo() {

        return new ApiInfoBuilder()
                .contact(new Contact(qfsyProperties.getContactName(),qfsyProperties.getContactUrl(), qfsyProperties.getContactEmail()))
                .title(qfsyProperties.getTitle())
                .version(qfsyProperties.getVersion())
                .build();
    }
}
